package com.ungs.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Restrictions;

import com.ungs.dao.DetalleStockDAO;
import com.ungs.entities.DetalleStock;
import com.ungs.entities.StockMaterial;

public class DetalleStockDAOImpl extends EntidadDAOImpl<DetalleStock> implements
		DetalleStockDAO {

	@SuppressWarnings("unchecked")
	@Override
	public List<DetalleStock> getDetalleByStockMaterial(
			StockMaterial stockMaterial) throws HibernateException {
		List<DetalleStock> detalleStockList = new ArrayList<DetalleStock>();
		logger.info("Obteniendo el detalle de stock por stock material");
		try {
			iniciaConexion();
			Criteria criteria = getSession().createCriteria(DetalleStock.class);
			Criteria critStock = criteria.createCriteria("stockMaterial");

			critStock.add(Restrictions.eq("id", stockMaterial.getId()));

			detalleStockList = (List<DetalleStock>) criteria.list();

		} catch (HibernateException he) {
			logger.error("Error al obtener el detalle de stock: "
					+ DetalleStock.class + "DAO");
			manejaExcepcion(he);
			throw he;
		} finally {
			getSession().close();
		}
		return detalleStockList;
	}

}
